package org.mybatis.generator.internal;

import org.mybatis.generator.api.ExtCommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.InnerClass;
import org.mybatis.generator.api.dom.java.InnerEnum;
import org.mybatis.generator.api.dom.java.InnerInterface;
import org.mybatis.generator.api.dom.java.JavaElement;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.PropertyRegistry;
import org.mybatis.generator.internal.util.StringUtility;

import javax.xml.bind.DatatypeConverter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import static org.mybatis.generator.internal.util.StringUtility.isTrue;

/*********************************************************
 * 文件名称：ExtDefaultCommentGenerator.java
 * 系统名称：cxycloud
 * 模块名称：org.mybatis.generator.internal
 * 功能说明：用于生成注释啥的
 * 开发人员 @author：caoxy
 * 开发时间 @date：2023/8/24 17:21
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
public class ExtDefaultCommentGenerator extends DefaultCommentGenerator implements ExtCommentGenerator {
    private final Properties properties = new Properties();
    private boolean suppressDate;

    private boolean suppressAllComments;

    /** If suppressAllComments is true, this option is ignored. */
    private boolean addRemarkComments;

    private SimpleDateFormat dateFormat;

    private String author;

    private FullyQualifiedJavaType generatedImport =
            new FullyQualifiedJavaType("jakarta.annotation.Generated"); //$NON-NLS-1$
    @Override
    public void addConfigurationProperties(Properties props) {
        super.addConfigurationProperties(props);
        this.author = props.getProperty("author");
        this.properties.putAll(props);

        suppressDate = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE));

        suppressAllComments = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_ALL_COMMENTS));

        addRemarkComments = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_ADD_REMARK_COMMENTS));

        if (isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_USE_LEGACY_GENERATED_ANNOTATION))) {
            generatedImport = new FullyQualifiedJavaType("javax.annotation.Generated"); //$NON-NLS-1$
        }

        String dateFormatString = properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_DATE_FORMAT);
        if (StringUtility.stringHasValue(dateFormatString)) {
            dateFormat = new SimpleDateFormat(dateFormatString);
        }
    }

    public void addInterfaceAnnotation(InnerInterface innerInterface, IntrospectedTable introspectedTable) {
        innerInterface.addJavaDocLine("/**");
        innerInterface.addJavaDocLine(" * @Title " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "表的Mapper类");
        innerInterface.addJavaDocLine(" * @author " + author);
        if (!suppressDate){
            innerInterface.addJavaDocLine(" * @date " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
        }
        innerInterface.addJavaDocLine(" * @description " + introspectedTable.getRemarks());
        addJavadocTag(innerInterface, true);
        innerInterface.addJavaDocLine(" */");
        innerInterface.addAnnotation("@Mapper");
    }

    public void addJavaFileComment(CompilationUnit compilationUnit) {
        compilationUnit.addFileCommentLine("/*");
        compilationUnit.addFileCommentLine(" * " + compilationUnit.getType().getShortName() + ".java");
        compilationUnit.addFileCommentLine(" * Copyright © 0000-9999 caoxy Technologies Inc.");
        compilationUnit.addFileCommentLine(" * All right reserved.");
        compilationUnit.addFileCommentLine(" * 奥里给");
        compilationUnit.addFileCommentLine(" */");
    }

    public void addComment(XmlElement xmlElement) {
        if (!this.suppressAllComments) {
            xmlElement.addElement(new TextElement("<!--"));
            StringBuilder sb = new StringBuilder();
            sb.append("  WARNING - ");
            xmlElement.addElement(new TextElement(sb.toString()));
            xmlElement.addElement(new TextElement("  这是工具生成代码，禁止手工修改"));
            xmlElement.addElement(new TextElement("-->"));
        }
    }

    public void addRootComment(XmlElement rootElement) {
    }

    protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
        javaElement.addJavaDocLine(" * <p>");
        StringBuilder sb = new StringBuilder();
        sb.append(" * ");
        if (markAsDoNotDelete) {
            sb.append("这是工具生成代码，禁止手工修改");
        }

        javaElement.addJavaDocLine(sb.toString());
    }

    protected String getDateString() {
        if (this.suppressDate) {
            return null;
        } else {
            return this.dateFormat != null ? this.dateFormat.format(new Date()) : (new Date()).toString();
        }
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
        if (!this.suppressAllComments) {
            innerClass.addJavaDocLine("/**");
            innerClass.addJavaDocLine(" * @Title " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "表的实体类");
            innerClass.addJavaDocLine(" * @description " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName());
            innerClass.addJavaDocLine(" */");
        }
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
        if (!this.suppressAllComments) {
            innerClass.addJavaDocLine("/**");
            innerClass.addJavaDocLine(" * @Title " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "表的实体类");
            innerClass.addJavaDocLine(" * @author " + this.author);
            if (!suppressDate) {
                innerClass.addJavaDocLine(" * @date " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
            }
            innerClass.addJavaDocLine(" * @description " + introspectedTable.getRemarks());
            this.addJavadocTag(innerClass, markAsDoNotDelete);
            innerClass.addJavaDocLine(" */");
        }
    }

    public void addExampleClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
        if (!this.suppressAllComments) {
            innerClass.addJavaDocLine("/**");
            if ("GeneratedCriteria".equals(innerClass.getType().getFullyQualifiedName())) {
                innerClass.addJavaDocLine(" * @Title " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "表的创建标准内部类");
            } else if ("Criteria".equals(innerClass.getType().getFullyQualifiedName())) {
                innerClass.addJavaDocLine(" * @Title " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "表的创建标准内部类");
            } else if ("Criterion".equals(innerClass.getType().getFullyQualifiedName())) {
                innerClass.addJavaDocLine(" * @Title " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "表的内部标准类");
            } else {
                innerClass.addJavaDocLine(" * @Title " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "表的内部类");
            }

            innerClass.addJavaDocLine(" * @description " + introspectedTable.getRemarks());
            innerClass.addJavaDocLine(" */");
        }
    }

    public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        if (!this.suppressAllComments && this.addRemarkComments) {
            topLevelClass.addJavaDocLine("/**");
            topLevelClass.addJavaDocLine(" * @author " + this.author);
            if (!suppressDate) {
                topLevelClass.addJavaDocLine(" * @date " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
            }
            String remarks = introspectedTable.getRemarks();
            if (this.addRemarkComments && StringUtility.stringHasValue(remarks)) {
                topLevelClass.addJavaDocLine(" * Database Table Remarks:");
                String[] remarkLines = remarks.split(System.getProperty("line.separator"));
                String[] var5 = remarkLines;
                int var6 = remarkLines.length;

                for(int var7 = 0; var7 < var6; ++var7) {
                    String remarkLine = var5[var7];
                    topLevelClass.addJavaDocLine(" * " + remarkLine);
                }
            }

            this.addJavadocTag(topLevelClass, true);
            topLevelClass.addJavaDocLine(" */");
        }
    }

    public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
        if (!this.suppressAllComments) {
            StringBuilder sb = new StringBuilder();
            innerEnum.addJavaDocLine("/**");
            innerEnum.addJavaDocLine(" * This enum was generated by MyBatis Generator.");
            sb.append(" * This enum corresponds to the database table ");
            sb.append(introspectedTable.getFullyQualifiedTable());
            innerEnum.addJavaDocLine(sb.toString());
            this.addJavadocTag(innerEnum, false);
            innerEnum.addJavaDocLine(" */");
        }
    }

    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (!this.suppressAllComments) {
            field.addJavaDocLine("/**");
            field.addJavaDocLine(" * " + field.getName() + " " + introspectedColumn.getRemarks());
            field.addJavaDocLine(" */");
        }
    }

    public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
        if (!this.suppressAllComments) {
            field.addJavaDocLine("/**");
            if ("orderByClause".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 排序字段");
            } else if ("distinct".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 是否过滤重复数据");
            } else if ("oredCriteria".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 过滤条件实例");
            } else if ("condition".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 条件");
            } else if ("criteria".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 标准集");
            } else if ("value".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 值/起始值");
            } else if ("secondValue".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 结束值");
            } else if ("noValue".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 空值");
            } else if ("singleValue".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 单一值");
            } else if ("betweenValue".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 区间比较符");
            } else if ("listValue".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 数组值");
            } else if ("typeHandler".equals(field.getName())) {
                field.addJavaDocLine(" * " + field.getName() + " 类型处理器");
            } else {
                field.addJavaDocLine(" * " + field.getName() + " " + field.getName());
            }

            field.addJavaDocLine(" */");
        }
    }

    public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
        if (!this.suppressAllComments) {
            StringBuilder sb = new StringBuilder();
            method.addJavaDocLine("/**");
            sb.append(" * ");
            if (method.isConstructor()) {
                sb.append("构造查询条件");
            }

            String method_name = method.getName();
            if ("setOrderByClause".equals(method_name)) {
                sb.append("设置排序字段");
            } else if ("setDistinct".equals(method_name)) {
                sb.append("设置过滤重复数据");
            } else if ("getOredCriteria".equals(method_name)) {
                sb.append("获取当前的查询条件实例");
            } else if ("isDistinct".equals(method_name)) {
                sb.append("是否过滤重复数据");
            } else if ("getOrderByClause".equals(method_name)) {
                sb.append("获取排序字段");
            } else if ("createCriteria".equals(method_name)) {
                sb.append("创建一个查询条件");
            } else if ("createCriteriaInternal".equals(method_name)) {
                sb.append("内部构建查询条件对象");
            } else if ("clear".equals(method_name)) {
                sb.append("清除查询条件");
            } else if ("countByExample".equals(method_name)) {
                sb.append("根据指定的条件获取数据库记录数");
            } else if ("countByExampleSuffix".equals(method_name)) {
                sb.append("根据指定的条件和表后缀获取数据库记录数");
            } else if ("deleteByExample".equals(method_name)) {
                sb.append("根据指定的条件删除数据库符合条件的记录");
            } else if ("deleteByExampleSuffix".equals(method_name)) {
                sb.append("根据指定的条件和表后缀删除数据库符合条件的记录");
            } else if ("deleteByPrimaryKey".equals(method_name)) {
                sb.append("根据主键删除数据库的记录");
            } else if ("deleteByPrimaryKeySuffix".equals(method_name)) {
                sb.append("根据主键和表后缀删除数据库的记录");
            } else if ("insert".equals(method_name)) {
                sb.append("新写入数据库记录");
            } else if ("insertSuffix".equals(method_name)) {
                sb.append("根据表后缀新写入数据库记录");
            } else if ("insertSelective".equals(method_name)) {
                sb.append("动态字段,写入数据库记录");
            } else if ("insertSelectiveSuffix".equals(method_name)) {
                sb.append("根据表后缀,动态字段,写入数据库记录");
            } else if ("selectByExample".equals(method_name)) {
                sb.append("根据指定的条件查询符合条件的数据库记录");
            } else if ("selectByExampleSuffix".equals(method_name)) {
                sb.append("根据指定的条件和表后缀查询符合条件的数据库记录");
            } else if ("selectByExampleWithPage".equals(method_name)) {
                sb.append("根据指定的条件分页查询符合条件的数据库记录");
            } else if ("selectByExampleWithPageSuffix".equals(method_name)) {
                sb.append("根据指定的条件分页和表后缀查询符合条件的数据库记录");
            } else if ("selectByPrimaryKey".equals(method_name)) {
                sb.append("根据指定主键获取一条数据库记录");
            } else if ("selectByPrimaryKeySuffix".equals(method_name)) {
                sb.append("根据指定主键和表后缀获取一条数据库记录");
            } else if ("updateByExampleSelective".equals(method_name)) {
                sb.append("动态根据指定的条件来更新符合条件的数据库记录");
            } else if ("updateByExampleSelectiveSuffix".equals(method_name)) {
                sb.append("动态根据指定的条件和表后缀来更新符合条件的数据库记录");
            } else if ("updateByExample".equals(method_name)) {
                sb.append("根据指定的条件来更新符合条件的数据库记录");
            } else if ("updateByExampleSuffix".equals(method_name)) {
                sb.append("根据指定的条件和表后缀来更新符合条件的数据库记录");
            } else if ("updateByPrimaryKeySelective".equals(method_name)) {
                sb.append("动态字段,根据主键来更新符合条件的数据库记录");
            } else if ("updateByPrimaryKeySelectiveSuffix".equals(method_name)) {
                sb.append("动态字段,根据主键和表后缀来更新符合条件的数据库记录");
            } else if ("updateByPrimaryKey".equals(method_name)) {
                sb.append("根据主键来更新符合条件的数据库记录");
            } else if ("updateByPrimaryKeySuffix".equals(method_name)) {
                sb.append("根据主键和表后缀来更新符合条件的数据库记录");
            } else if ("insertBatch".equals(method_name)) {
                sb.append("批量写入数据库记录");
            } else if ("insertBatchSuffix".equals(method_name)) {
                sb.append("根据表后缀批量写入数据库记录");
            } else if ("or".equals(method_name)) {
                if (method.getParameters() == null) {
                    sb.append("创建一个新的或者查询条件");
                } else {
                    sb.append("根据主键来更新符合条件的数据库记录");
                }
            } else if ("isValid".equals(method_name)) {
                sb.append("是否验证");
            } else if ("getAllCriteria".equals(method_name)) {
                sb.append("获取所有条件集");
            } else if ("getCriteria".equals(method_name)) {
                sb.append("获取条件集");
            } else if ("addCriterion".equals(method_name)) {
                sb.append("增加条件");
            } else if ("getCondition".equals(method_name)) {
                sb.append("获取条件");
            } else if ("getValue".equals(method_name)) {
                sb.append("获取值/起始值");
            } else if ("getSecondValue".equals(method_name)) {
                sb.append("获取结束值");
            } else if ("isNoValue".equals(method_name)) {
                sb.append("是否空值");
            } else if ("isSingleValue".equals(method_name)) {
                sb.append("是否唯一值");
            } else if ("isBetweenValue".equals(method_name)) {
                sb.append("是否区间值");
            } else if ("isListValue".equals(method_name)) {
                sb.append("是否数组值");
            } else if ("getTypeHandler".equals(method_name)) {
                sb.append("获取处理器");
            }

            if (introspectedTable != null) {
                sb.append(":");
                sb.append(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName());
            }

            method.addJavaDocLine(sb.toString());
            List<Parameter> parameterList = method.getParameters();
            int length = 0;
            if (!parameterList.isEmpty()) {
                method.addJavaDocLine(" *");

                Parameter parameter;
                for(Iterator var7 = parameterList.iterator(); var7.hasNext(); length = length < parameter.getName().length() ? parameter.getName().length() : length) {
                    parameter = (Parameter)var7.next();
                }
            }

            for(Iterator var13 = parameterList.iterator(); var13.hasNext(); method.addJavaDocLine(sb.toString())) {
                Parameter parameter = (Parameter)var13.next();
                sb.setLength(0);
                sb.append(" * @param ");
                String paramterName = parameter.getName();
                sb.append(this.padRight(paramterName, length, ' '));
                if ("orderByClause".equals(paramterName)) {
                    sb.append(" 排序字段");
                } else if ("distinct".equals(paramterName)) {
                    sb.append(" 是否过滤重复数据");
                } else if ("criteria".equals(paramterName)) {
                    sb.append(" 过滤条件实例");
                } else if ("example".equals(paramterName)) {
                    sb.append(" Example对象");
                } else if ("key".equals(paramterName)) {
                    sb.append(" 主键对象");
                } else if ("record".equals(paramterName)) {
                    sb.append(" 实体对象");
                } else if ("row".equals(paramterName)) {
                    sb.append(" 实体对象");
                } else if ("tableSuffix".equals(paramterName)) {
                    sb.append(" 表后缀");
                } else if ("rowBounds".equals(paramterName)) {
                    sb.append(" 分页对象");
                } else if ("tenantId".equals(paramterName)) {
                    sb.append(" 租户号");
                } else if ("records".equals(paramterName)) {
                    sb.append(" 记录集");
                } else if ("rows".equals(paramterName)) {
                    sb.append(" 记录集");
                } else if ("tableSuffixList".equals(paramterName)) {
                    sb.append(" 表后缀集");
                } else if ("condition".equals(paramterName)) {
                    sb.append(" 条件");
                } else if ("value".equals(paramterName)) {
                    sb.append(" 值");
                } else if ("value1".equals(paramterName)) {
                    sb.append(" 起始值");
                } else if ("value2".equals(paramterName)) {
                    sb.append(" 结束值");
                } else if ("property".equals(paramterName)) {
                    sb.append(" 属性");
                } else {
                    Iterator var10 = introspectedTable.getPrimaryKeyColumns().iterator();

                    while(var10.hasNext()) {
                        IntrospectedColumn column = (IntrospectedColumn)var10.next();
                        if (column.getJavaProperty().equals(paramterName)) {
                            sb.append(" " + column.getRemarks());
                            break;
                        }
                    }
                }
            }

            if (method.getReturnType() != null) {
                if (parameterList.isEmpty()) {
                    method.addJavaDocLine(" * ");
                }

                sb.setLength(0);
                method.getReturnType().ifPresent(s->{
                    sb.append(" * @return " + s.getShortName());
                });
                if ("countByExample".equals(method_name)) {
                    sb.append(" 符合条件的记录数");
                } else if (!"deleteByExample".equals(method_name) && !"deleteByPrimaryKey".equals(method_name)) {
                    if (!"insert".equals(method_name) && !"insertSelective".equals(method_name) && !"insertBatch".equals(method_name)) {
                        if (!"selectByExample".equals(method_name) && !"selectByExampleWithPage".equals(method_name)) {
                            if ("selectByPrimaryKey".equals(method_name)) {
                                sb.append(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName()).append(" 实体对象");
                            } else if (!"updateByExampleSelective".equals(method_name) && !"updateByExample".equals(method_name) && !"updateByPrimaryKeySelective".equals(method_name) && !"updateByPrimaryKey".equals(method_name)) {
                                if (!"getAllCriteria".equals(method_name) && !"getCriteria".equals(method_name)) {
                                    if (!"createCriteria".equals(method_name) && !"createCriteriaInternal".equals(method_name)) {
                                        if ("getOrderByClause".equals(method_name)) {
                                            sb.append(" 排序规则");
                                        } else if ("isDistinct".equals(method_name)) {
                                            sb.append(" 是否过滤重复");
                                        } else if ("getOredCriteria".equals(method_name)) {
                                            sb.append(" 获取标准集");
                                        } else if ("or".equals(method_name)) {
                                            sb.append(" 标准条件式");
                                        } else if ("getCondition".equals(method_name)) {
                                            sb.append(" 条件");
                                        } else if ("getValue".equals(method_name)) {
                                            sb.append(" 值/起始值");
                                        } else if ("getSecondValue".equals(method_name)) {
                                            sb.append(" 结束值");
                                        } else if ("isNoValue".equals(method_name)) {
                                            sb.append(" 是否空值");
                                        } else if ("isSingleValue".equals(method_name)) {
                                            sb.append(" 是否唯一值");
                                        } else if ("isBetweenValue".equals(method_name)) {
                                            sb.append(" 是否区间值");
                                        } else if ("isListValue".equals(method_name)) {
                                            sb.append(" 是否数组值");
                                        } else if ("getTypeHandler".equals(method_name)) {
                                            sb.append(" 处理器");
                                        } else if ("isValid".equals(method_name)) {
                                            sb.append(" 是否有效");
                                        }
                                    } else {
                                        sb.append(" 标准条件式");
                                    }
                                } else {
                                    sb.append(" 标准集");
                                }
                            } else {
                                sb.append(" 更新影响的记录数");
                            }
                        } else {
                            sb.append(" 符合条件的记录");
                        }
                    } else {
                        sb.append(" 写入影响的记录数");
                    }
                } else {
                    sb.append(" 删除影响的记录数");
                }

                method.addJavaDocLine(sb.toString());
            }

            method.addJavaDocLine(" */");
        }
    }

    public void addExampleMethodComment(Method method, IntrospectedColumn introspectedColumn) {
        if (!this.suppressAllComments) {
            StringBuilder sb = new StringBuilder();
            method.addJavaDocLine("/**");
            sb.append(" * ");
            String methodName = method.getName();
            if (introspectedColumn != null) {
                methodName = methodName.replace(this.capture(introspectedColumn.getJavaProperty()), "");
            }

            if ("andIsNull".equals(methodName)) {
                sb.append("条件为空");
            } else if ("andIsNotNull".equals(methodName)) {
                sb.append("条件不为空");
            } else if ("andEqualTo".equals(methodName)) {
                sb.append("条件相等");
            } else if ("andNotEqualTo".equals(methodName)) {
                sb.append("条件不相等");
            } else if ("andGreaterThan".equals(methodName)) {
                sb.append("条件大于");
            } else if ("andGreaterThanOrEqualTo".equals(methodName)) {
                sb.append("条件大于等于");
            } else if ("andLessThan".equals(methodName)) {
                sb.append("条件小于");
            } else if ("andLessThanOrEqualTo".equals(methodName)) {
                sb.append("条件小于等于");
            } else if ("andLike".equals(methodName)) {
                sb.append("条件相似");
            } else if ("andNotLike".equals(methodName)) {
                sb.append("条件不相似");
            } else if ("andIn".equals(methodName)) {
                sb.append("条件在范围");
            } else if ("andNotIn".equals(methodName)) {
                sb.append("条件不在范围");
            } else if ("andBetween".equals(methodName)) {
                sb.append("条件在区间");
            } else if ("andNotBetween".equals(methodName)) {
                sb.append("条件不在区间");
            } else if ("Criterion".equals(methodName)) {
                sb.append("标准条件类构造方法");
            }

            if (introspectedColumn != null) {
                sb.append(":");
                sb.append(introspectedColumn.getRemarks());
            }

            method.addJavaDocLine(sb.toString());
            List<Parameter> parameterList = method.getParameters();
            int length = 0;
            if (!parameterList.isEmpty()) {
                method.addJavaDocLine(" *");

                Parameter parameter;
                for(Iterator var7 = parameterList.iterator(); var7.hasNext(); length = length < parameter.getName().length() ? parameter.getName().length() : length) {
                    parameter = (Parameter)var7.next();
                }
            }

            for(Iterator var11 = parameterList.iterator(); var11.hasNext(); method.addJavaDocLine(sb.toString())) {
                Parameter parameter = (Parameter)var11.next();
                sb.setLength(0);
                sb.append(" * @param ");
                String paramterName = parameter.getName();
                sb.append(this.padRight(paramterName, length, ' '));
                if ("value".equals(paramterName)) {
                    sb.append(" 值");
                } else if ("value1".equals(paramterName)) {
                    sb.append(" 起始值");
                } else if ("value2".equals(paramterName)) {
                    sb.append(" 结束值");
                } else if ("property".equals(paramterName)) {
                    sb.append(" 属性");
                } else if ("condition".equals(paramterName)) {
                    sb.append(" 条件");
                } else if ("typeHandler".equals(paramterName)) {
                    sb.append(" 处理器");
                } else if ("secondValue".equals(paramterName)) {
                    sb.append(" 结束值");
                } else if (introspectedColumn != null) {
                    sb.append(" " + introspectedColumn.getRemarks());
                }
            }

            if (method.getReturnType() != null) {
                if (parameterList.isEmpty()) {
                    method.addJavaDocLine(" * ");
                }

                sb.setLength(0);
                sb.append(" * @return ");
                sb.append("标准");
                method.addJavaDocLine(sb.toString());
            }

            method.addJavaDocLine(" */");
        }
    }

    public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (!this.suppressAllComments) {
            StringBuilder sb = new StringBuilder();
            method.addJavaDocLine("/**");
            sb.append(" * 获取 ");
            sb.append(introspectedColumn.getRemarks()).append(" 字段:");
            sb.append(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName());
            sb.append('.');
            sb.append(introspectedColumn.getActualColumnName());
            method.addJavaDocLine(sb.toString());
            method.addJavaDocLine(" *");
            sb.setLength(0);
            sb.append(" * @return ");
            sb.append(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName());
            sb.append('.');
            sb.append(introspectedColumn.getActualColumnName());
            sb.append(", ");
            sb.append(introspectedColumn.getRemarks());
            method.addJavaDocLine(sb.toString());
            method.addJavaDocLine(" */");
        }
    }

    public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (!this.suppressAllComments) {
            StringBuilder sb = new StringBuilder();
            method.addJavaDocLine("/**");
            sb.append(" * 设置 ");
            sb.append(introspectedColumn.getRemarks()).append(" 字段:");
            sb.append(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName());
            sb.append('.');
            sb.append(introspectedColumn.getActualColumnName());
            method.addJavaDocLine(sb.toString());
            method.addJavaDocLine(" *");
            Parameter parm = (Parameter)method.getParameters().get(0);
            sb.setLength(0);
            sb.append(" * @param ");
            sb.append(parm.getName());
            sb.append(" the value for ");
            sb.append(introspectedTable.getFullyQualifiedTable().getIntrospectedTableName());
            sb.append('.');
            sb.append(introspectedColumn.getActualColumnName());
            sb.append(", ");
            sb.append(introspectedColumn.getRemarks());
            method.addJavaDocLine(sb.toString());
            method.addJavaDocLine(" */");
        }
    }

    public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> imports) {
        imports.add(generatedImport);
        String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().toString();
        method.addAnnotation(this.getGeneratedAnnotation(comment));
    }

    public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
        imports.add(generatedImport);
        String comment = "Source field: " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "." + introspectedColumn.getActualColumnName();
        method.addAnnotation(this.getGeneratedAnnotation(comment));
    }

    public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> imports) {
        imports.add(generatedImport);
        String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName();
        field.addAnnotation(this.getGeneratedAnnotation(comment));
    }

    public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
        imports.add(generatedImport);
        String comment = "Source field: " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName() + "." + introspectedColumn.getActualColumnName();
        field.addAnnotation(this.getGeneratedAnnotation(comment));
    }

    public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> imports) {
        imports.add(generatedImport);
        String comment = "Source Table: " + introspectedTable.getFullyQualifiedTable().getIntrospectedTableName();
        innerClass.addAnnotation(this.getGeneratedAnnotation(comment));
    }

    private String getGeneratedAnnotation(String comment) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("@Generated(");
        if (this.suppressAllComments) {
            buffer.append('"');
        } else {
            buffer.append("value=\"");
        }

        buffer.append(MyBatisGenerator.class.getName());
        buffer.append('"');
        if (!this.suppressDate && !this.suppressAllComments) {
            buffer.append(", date=\"");
            buffer.append(DatatypeConverter.printDateTime(Calendar.getInstance()));
            buffer.append('"');
        }

        if (!this.suppressAllComments) {
            buffer.append(", comments=\"");
            buffer.append(comment);
            buffer.append('"');
        }

        buffer.append(')');
        return buffer.toString();
    }

    private String padRight(String str, int len, char ch) {
        int diff = len - str.length();
        if (diff <= 0) {
            return str;
        } else {
            char[] charr = new char[len];
            System.arraycopy(str.toCharArray(), 0, charr, 0, str.length());

            for(int i = str.length(); i < len; ++i) {
                charr[i] = ch;
            }

            return new String(charr);
        }
    }

    private String capture(String str) {
        char[] cs = str.toCharArray();
        cs[0] = (char)(cs[0] - 32);
        return String.valueOf(cs);
    }
}
